#include "Enemy.h"

Enemy::Enemy() 
	: mActive(false)//remind peter why this is better? and about consts
{
	
}

Enemy::~Enemy()
{

}

void Enemy::Load()
{
	mSprite.Load("pikachu.png");
}

void Enemy::Unload()
{
	mSprite.Unload();
}

void Enemy::Update(float deltaTime)
{
	if (mActive)
	{
		delay-=deltaTime;
		if ( delay <= 0.0f)
		{
			SVector2 temporary=mVelocity;

			temporary.x=-mVelocity.x;
			mVelocity=temporary;
			delay=RandomFloat(0.1f,0.7f);
		}
		mPosition += mVelocity * deltaTime;
		const int kWinWidth = IniFile_GetInt("WinWidth",800);//the number is just incase the program cant get the int. Number is basically a default
		const int kWinHeight = IniFile_GetInt("WinHeight",600);
		const int kThreshold = mSprite.GetWidth();
		if(mPosition.x < -kThreshold || mPosition.x > kWinWidth+kThreshold || mPosition.y < -kThreshold || mPosition.y > kWinHeight + kThreshold)
		{
			Kill();
		}
	}

}

void Enemy::Render()
{
	if (mActive)
	{ 
		const int width = mSprite.GetWidth();
		const int height = mSprite.GetHeight();
		SVector2 offset(width * 0.5f,height * 0.5f);
		SVector2 renderPosition = mPosition - offset;
		mSprite.SetPosition(renderPosition);
		mSprite.Render();

	}
	
}

void Enemy::Spawn(const SVector2& pos)
{
	mPosition = pos;
	mVelocity = SVector2(200.0f,200.f);
	mActive = true;
}

void Enemy::Kill()
{
	
	mActive = false;
	
}